import { defineStore } from 'pinia'
import { useRouter } from 'vue-router'
import dynamicRoutes from '@/router/dynamicRoutes'
import constantRoutes from '@/router/constantRoutes'

const useUserStore = defineStore('user', {
	state: () => ({
		// 是否登录
		isLogin: false,

		// 菜单列表
		menuList: [] as any
	}),

	actions: {
		// 设置登录状态
		setLoginState(state: boolean) {
			this.isLogin = state
		},

		// 获取菜单列表
		getMenuList() {
			const dynamic = JSON.parse(JSON.stringify(dynamicRoutes))
			const constant = JSON.parse(JSON.stringify(constantRoutes))
			// const routes = constant.concat(dynamic)
			const router = useRouter()

			router.addRoute(dynamic)

			// this.menuList = dynamicRoutes
		}
	}
})

export default useUserStore
